package com.wanxi.dangdang.mapper;

import com.wanxi.dangdang.model.vo.AdminFindPageVo;
import com.wanxi.dangdang.model.vo.RegionVo;
import org.apache.ibatis.annotations.Many;
import org.apache.ibatis.annotations.Result;
import org.apache.ibatis.annotations.Results;
import org.apache.ibatis.annotations.Select;

import java.util.List;

/**
 * @Author: WangRui
 * @Description:
 * @Date: Created in 2021/9/9 0009
 * @Version: 1.0
 */
public interface RegionMapper {

    @Select("select * from region where level = 1")
    @Results({
            @Result(property = "label",column = "name"),
            @Result(property = "level",column = "level"),
            @Result(property = "code",column = "id"),
            @Result(property = "children",
                    column = "id",
                    javaType = List.class,
                    many = @Many(select = "com.wanxi.dangdang.mapper.RegionMapper.findTwo"))
    })
    List<RegionVo> findOne();


    @Select("select * from region where level = 2 and pid = #{pid}")
    @Results({
            @Result(property = "label",column = "name"),
            @Result(property = "level",column = "level"),
            @Result(property = "code",column = "id"),
            @Result(property = "children",
                    column = "id",
                    javaType = List.class,
                    many = @Many(select = "com.wanxi.dangdang.mapper.RegionMapper.findThere"))
    })
    List<RegionVo> findTwo(Integer id);

    @Select("select * from region where level = 3 and pid = #{pid}")
    @Results({
            @Result(property = "label",column = "name"),
            @Result(property = "level",column = "level"),
            @Result(property = "code",column = "id"),
    })
    List<RegionVo> findThere(Integer id);
}
